package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.search.AlbumInfoIndex;
import com.atguigu.tingshu.query.search.AlbumIndexQuery;
import com.atguigu.tingshu.search.service.SearchService;
import com.atguigu.tingshu.vo.search.AlbumSearchResponseVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "搜索专辑管理")
@RestController
@RequestMapping("api/search")
@SuppressWarnings({"all"})
public class SearchApiController {

    @Autowired
    private SearchService searchService;

    /**
     * 上架索引库
     * @param albumId 专辑id
     * @return
     */
    @Operation(summary = "上架专辑-导入索引库 //为了测试")
    @GetMapping("/albumInfo/upperAlbum/{albumId}")
    public Result upperAlbum(@PathVariable Long albumId) {
        searchService.upperAlbum(albumId);
        return Result.ok();
    }

    /**
     * 下架索引库
     * @param albumId
     * @return
     */
    @Operation(summary = "下架专辑-删除文档 //ceshi ")
    @DeleteMapping("/albumInfo/lowerAlbum/{albumId}")

    public Result lowerAlbum(@PathVariable Long albumId) {
        searchService.lowerAlbum(albumId);
        return Result.ok();
    }

    @Operation(summary = "根据用户选择关键字/专辑id/专辑标签进行专辑检索")
    @PostMapping("/albumInfo")
    public Result<AlbumSearchResponseVo> search(@RequestBody AlbumIndexQuery query) {

        AlbumSearchResponseVo responseVo = searchService.search(query);
        return Result.ok(responseVo);
    }

    /**
     * 根据一级分类下的三级分类 查询热度排行前6的对象信息
     * @param category1Id   一级分类
     * @return 首页三级分类热度排行前6
     */
    @Operation(summary = "根据一级分类下的三级分类 查询热度排行前6的对象信息")
    @GetMapping("/albumInfo/channel/{category1Id}")
    public Result<List<Map<String, Object>>> getByCategory3Top6(@PathVariable Long category1Id) {

        List<Map<String, Object>> list = searchService.getByCategory3Top6(category1Id);
        return Result.ok(list);
    }



    /**
     * 关键字自动补全
     *
     * @param keyword
     * @return
     */
    @Operation(summary = "关键字自动补全")
    @GetMapping("/albumInfo/completeSuggest/{keyword}")
    public Result<List<String>> completeSuggest(@PathVariable String keyword) {
        List<String> list = searchService.completeSuggest(keyword);
        return Result.ok(list);
    }


    /**
     * 获取全部数据的
     * @return
     */
    @Operation(summary = "构建热度排行,根据一级分类id/统计类型查询ES")
    @GetMapping("/albumInfo/updateLatelyAlbumRanking")
    public Result  updateLatelyAlbumRanking(){
        searchService.updateLatelyAlbumRanking();
        return Result.ok();
    }


    /**
     * 获取Redis中不同分类下不同排序方式-专辑排行榜 获取最终结果的
     *
     * @param category1Id
     * @param dimension
     * @return
     */
    @Operation(summary = "获取Redis中不同分类下不同排序方式-专辑排行榜")
    @GetMapping("/albumInfo/findRankingList/{category1Id}/{dimension}")
    public Result<List<AlbumInfoIndex>> getRankingList(@PathVariable Long category1Id, @PathVariable String dimension) {
        List<AlbumInfoIndex> list = searchService.getRankingList(category1Id, dimension);
        return Result.ok(list);
    }
}

